//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by Corgi on 17/3/19.
//  Copyright © 2017年 cocoaHangTou. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(title: String? = nil, imageName: String? = nil,backImageName: String? = nil, target: Any?, action: Selector?) {

        let btn = UIButton()
        
        if let imgName = imageName {
            
            btn.setImage(UIImage(named:imgName), for: .normal)
            
            btn.setImage(UIImage(named:imgName + "_highlighted"), for: .highlighted)
        }
        
        btn.setTitle(title, for: .normal)
        
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        if let t = target, let a = action {
            
            btn.addTarget(t, action: a, for: .touchUpInside)
            
        }
        
        btn.sizeToFit()
        
        self.init()
        
        customView = btn
    }

}
